home *** CD-ROM | disk | FTP | other *** search
-
- #pragma once
-
- #ifndef __MORESTRINGS__
- #define __MORESTRINGS__
-
- #include "MoreAEM.h"
-
- #include <Types.h>
- #include <TextUtils.h>
-
- enum
- {
- kStringStart = 0,
- kStringEnd = 0x7FFFFFFF,
- kStringAllocationChunk = 32,
- kSubstringNotFound = -1
- };
-
-
- //========================================================================================
- // CLASS TString
- //========================================================================================
-
- class TString
- {
- public:
- TString();
- TString(const TString&);
- TString(const TDescriptor&);
-
- TString(UInt32 maximumSize);
- TString(unsigned char* stringExternalStorage, UInt32 maximumSize, UInt32 currentSizeInBytes = 0, ScriptCode stringScript = smSystemScript, LangCode stringLanguage = scriptDefLang);
- TString(unsigned char*); // Str255 assumed
-
-
- ~TString();
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: Common methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- operator TDescriptor() const;
-
- TString& operator=(const TString&);
- TString& operator=(const TDescriptor& desc);
-
- Boolean operator==(const TString& rhs) const { return this->ExactlyEqual(rhs); }
-
- UInt32 StringLength() const;
- UInt32 SizeInBytes() const;
- UInt32 MaximumSizeInBytes() const;
-
- Boolean Empty() const;
- void ClearString();
-
- SInt16 CompareStringOrder(const TString& stringToCompare) const;
- Boolean Equal(const TString&) const;
- Boolean ExactlyEqual(const TString&) const;
- Boolean NearlyEqual(const TString&) const;
-
- SInt32 FindOffset(const TString& searchPattern) const;
- Boolean Contains(const TString& searchPattern) const;
-
- void Delete(UInt32 destStartIndex, UInt32 destEndIndex);
- Boolean InsertAfter(UInt32 destStartIndex, const TString& replaceWith);
- void Replace(UInt32 destStartIndex, UInt32 destEndIndex, const TString& replaceWith);
- void Append(const TString&);
- void Prefix(const TString&);
-
- void ConvertToStr255(Str255 destination);
-
-
- operator const unsigned char*() const { ((TString*)this)->ExpandToFit(256); return fStr; }
- operator unsigned char*() { ((TString*)this)->ExpandToFit(256); return fStr; }
-
- const unsigned char* TextStart() const { return &fStr[1]; }
- unsigned char* TextStart() { return &fStr[1]; }
-
- ScriptCode StringScript() const { return fStringScript; }
- LangCode StringLanguage() const { return fStringLanguage; }
-
-
- protected:
-
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: protected methods
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- Boolean Equivalent(const TString& compareWith) const;
-
- void SetLength(UInt32 newLength);
- void CorrectInternalLength() const;
- void ExpandToFit(UInt32 spaceRequired);
-
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: Fields
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- //
- // Points to a length-byte + string (pascal format string)
- // If the actual length of the string is longer than
- // 255 bytes, then the length byte will be 255.
- //
- unsigned char* fStr;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: A little bit less than 16 bytes follows...
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- //
- // String script and language
- //
- ScriptCode fStringScript;
- LangCode fStringLanguage;
-
- //
- // Keep track of important information
- // about the string we point to
- //
- UInt32 fActualSizeInBytes;
- UInt32 fMaximumSizeInBytes;
- Boolean fStorageAllocatedInHeap;
-
- };
-
- enum
- {
- kStackBasedStringStorageUnits = 256
- };
-
- //========================================================================================
- // CLASS TStackBasedString
- //========================================================================================
-
- class TStackBasedString : public TString
- {
- public:
-
- TStackBasedString() : TString(fStringStorage, kStackBasedStringStorageUnits * sizeof(unsigned char)) { fStringStorage[0] = 0; }
- TStackBasedString(const TString&);
-
- TString& operator=(const TString& rhs) { return TString::operator=(rhs); }
- TString& operator=(const TDescriptor& desc) { return TString::operator=(desc); }
-
- Boolean operator==(const TString& rhs) const { return TString::operator==(rhs); }
-
- protected:
-
- unsigned char fStringStorage[kStackBasedStringStorageUnits];
-
- };
-
- #endif
-